package engine.individuals.util;

import java.util.Comparator;

import engine.ObjectiveFunction;

public class IndividualsComparator<T> implements Comparator<T> {

	private ObjectiveFunction<T> objFunction;

	public IndividualsComparator(ObjectiveFunction<T> objFunction) {
		this.objFunction = objFunction;
	}
	
	@Override
	public int compare(
			T o1,
			T o2) {
		
		double val1 = objFunction.compute(o1);
		double val2 = objFunction.compute(o2);
		if (val1 > val2) {
			return 1;
		} else if (val1 < val2) {
			return -1;
		} else {
			return 0;
		}
	}

}
